package com.ruoyi.cderp.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.cderp.domain.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.cderp.service.ITblSaleOrderService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 销售订单Controller
 *
 * @author ruoyi
 * @date 2025-04-15
 */
@RestController
@RequestMapping("/system/order")
public class TblSaleOrderController extends BaseController
{
    @Autowired
    private ITblSaleOrderService tblSaleOrderService;

    /**
     * 查询销售订单列表
     */
    @PreAuthorize("@ss.hasPermi('system:order:list')")
    @GetMapping("/list")
    public TableDataInfo list(TblSaleOrder tblSaleOrder)
    {
        startPage();
        List<TblSaleOrder> list = tblSaleOrderService.selectTblSaleOrderList(tblSaleOrder);
        return getDataTable(list);
    }

    /**
     * 导出销售订单列表
     */
    @PreAuthorize("@ss.hasPermi('system:order:export')")
    @Log(title = "销售订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TblSaleOrder tblSaleOrder)
    {
        List<TblSaleOrder> list = tblSaleOrderService.selectTblSaleOrderList(tblSaleOrder);
        ExcelUtil<TblSaleOrder> util = new ExcelUtil<TblSaleOrder>(TblSaleOrder.class);
        util.exportExcel(response, list, "销售订单数据");
    }

    /**
     * 获取销售订单详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:order:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(tblSaleOrderService.selectTblSaleOrderById(id));
    }

    /**
     * 新增销售订单
     */
    @PreAuthorize("@ss.hasPermi('system:order:add')")
    @Log(title = "销售订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TblSaleOrder tblSaleOrder)
    {
        return toAjax(tblSaleOrderService.insertTblSaleOrder(tblSaleOrder));
    }

    /**
     * 修改销售订单
     */
    @PreAuthorize("@ss.hasPermi('system:order:edit')")
    @Log(title = "销售订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TblSaleOrder tblSaleOrder)
    {
        return toAjax(tblSaleOrderService.updateTblSaleOrder(tblSaleOrder));
    }

    /**
     * 删除销售订单
     */
    @PreAuthorize("@ss.hasPermi('system:order:remove')")
    @Log(title = "销售订单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(tblSaleOrderService.deleteTblSaleOrderByIds(ids));
    }

    /**
     * 获取销售参数设置数据
     */
    @PreAuthorize("@ss.hasPermi('system:saleConfig:index')")
    @GetMapping("/index")
    public AjaxResult index() {
        return success(tblSaleOrderService.selectTblSaleConfigInfo());
    }

    /**
     * 修改销售参数设置
     */
    @PreAuthorize("@ss.hasPermi('system:saleConfig:update')")
    @Log(title = "销售参数设置", businessType = BusinessType.UPDATE)
    @PutMapping("/update")
    public AjaxResult update(@RequestBody TblSaleConfig tblSaleConfig) {
        return toAjax(tblSaleOrderService.updateTblSaleConfig(tblSaleConfig));
    }

    /**
     * 获取仓库
     */
    @PreAuthorize("@ss.hasPermi('system:order:center')")
    @GetMapping("/center")
    public TableDataInfo center(Center center) {
        List<BaseDataStoreCenter> list = tblSaleOrderService.center(center);
        return getDataTable(list);
    }

    /**
     * 获取客户
     */
    @PreAuthorize("@ss.hasPermi('system:order:customer')")
    @GetMapping("/customer")
    public TableDataInfo customer() {
        List<BaseDataCustomer> list = tblSaleOrderService.customer();
        return getDataTable(list);
    }

}
